$(function(){
    layui.use(['laytpl', 'layer','locals','table'],function(){
        let laytpl = layui.laytpl;
        let layer = layui.layer;
        let locals = layui.locals;
        let table = layui.table;

        let parentParams = locals.get('parentParams');
        function topChart() {
            let myChart = echarts.init(document.getElementById('top-chart'),'jyt-dark');
            let option = {
                title: {
                    text: '折线图堆叠'
                },
                tooltip: {
                    trigger: 'axis'
                },
                legend: {
                    data: ['邮件营销', '联盟广告', '视频广告', '直接访问', '搜索引擎']
                },
                grid: {
                    left: '3%',
                    right: '4%',
                    bottom: '3%',
                    containLabel: true
                },
                xAxis: {
                    type: 'category',
                    boundaryGap: false,
                    data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
                },
                yAxis: {
                    type: 'value'
                },
                series: [
                    {
                        name: '邮件营销',
                        type: 'line',
                        stack: '总量',
                        data: [120, 132, 101, 134, 90, 230, 210]
                    },
                    {
                        name: '联盟广告',
                        type: 'line',
                        stack: '总量',
                        data: [220, 182, 191, 234, 290, 330, 310]
                    },
                    {
                        name: '视频广告',
                        type: 'line',
                        stack: '总量',
                        data: [150, 232, 201, 154, 190, 330, 410]
                    },
                    {
                        name: '直接访问',
                        type: 'line',
                        stack: '总量',
                        data: [320, 332, 301, 334, 390, 330, 320]
                    },
                    {
                        name: '搜索引擎',
                        type: 'line',
                        stack: '总量',
                        data: [820, 932, 901, 934, 1290, 1330, 1320]
                    }
                ]
            };
            myChart.setOption(option);
            window.addEventListener("resize", function () {
                myChart.resize();
            });
        }

        function bottomChart() {
            let myChart = echarts.init(document.getElementById('bottom-chart'),'jyt-dark');
            let option = {
                title: {
                    text: '堆叠柱状图'
                },
                tooltip: {
                    trigger: 'axis'
                },
                legend: {
                    data: ['邮件营销', '联盟广告', '视频广告', '直接访问', '搜索引擎']
                },
                grid: {
                    left: '3%',
                    right: '4%',
                    bottom: '3%',
                    containLabel: true
                },
                xAxis: {
                    type: 'category',
                    boundaryGap: true,
                    data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
                },
                yAxis: {
                    type: 'value'
                },
                series: [
                    {
                        name: '邮件营销',
                        type: 'bar',
                        stack: '总量',
                        data: [120, 132, 101, 134, 90, 230, 210]
                    },
                    {
                        name: '联盟广告',
                        type: 'bar',
                        stack: '总量',
                        data: [220, 182, 191, 234, 290, 330, 310]
                    },
                    {
                        name: '视频广告',
                        type: 'bar',
                        stack: '总量',
                        data: [150, 232, 201, 154, 190, 330, 410]
                    },
                    {
                        name: '直接访问',
                        type: 'bar',
                        stack: '总量',
                        data: [320, 332, 301, 334, 390, 330, 320]
                    },
                    {
                        name: '搜索引擎',
                        type: 'bar',
                        stack: '总量',
                        data: [820, 932, 901, 934, 1290, 1330, 1320]
                    }
                ]
            };
            myChart.setOption(option);
            window.addEventListener("resize", function () {
                myChart.resize();
            });
        }
        topChart();
        bottomChart();

        function tableMonth(){
            // 拼接表格col(当月)
            let year = new Date().getFullYear();
            let month = new Date().getMonth() + 1;
            let mm = month < 10 ? "0" + month : month;
            var len = getAMonthDays(year, month); //本月天数
            let cols = [{field: 'itemName', title: '项目',width:100}];
            for (var i = 1; i <= len; i++) {
                var day = i < 10 ? "0" + i : i;
                cols.push({field: mm + '/' + day, title: month + '/' + i});
            };
            table.render({
                elem: '#top-table'
                , id: 'top-table'
                , size: 'sm'
                , data: [
                    {'itemName': '目标MPCS','07/01': 54,'07/02': 54,'07/03': 54,'07/04': 54,'07/05': 54,'07/06': 54},
                    {'itemName': '实际MPCS','07/01': 50,'07/02': 50,'07/03': 50,'07/04': 50,'07/05': 50,'07/06': 50}
                ]
                , size: 'sm'
                , cols: [cols]
            });
        }
        tableMonth()

        $('.secondPage').on('click','.layer-trigger',function () {
            let id = $(this).attr('id');
            let layerIdx = layer.open({
                type: 2,
                title: id + '三阶页面',
                shadeClose: false,
                shade: 0.2,
                area: ['80%', '80%'],
                maxmin: true,
                content: ['/iframePages/thirdPage.do', 'no'],
            });
            // setTimeout(function () {
            //     layer.full(layerIdx);
            // },3000)
        });

    });
});